package com.yue.lin.controller;

import com.yue.lin.domain.Permission;
import com.yue.lin.domain.User;
import com.yue.lin.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.UUID;

/**
 * @author zhengyl
 * @description
 * @date 2020-04-02 10:11
 */
@RestController
@RequestMapping("user")
public class UserController {
    @Autowired
    UserService userService;

    @GetMapping("add")
    public boolean add() {
        User user = new User();
        user.setName("zs");
        user.setPassword("123");
        user.setSalt(UUID.randomUUID().toString().replace("-", ""));
        return userService.add(user);
    }

    @GetMapping("current")
    public User current() {
        User current = userService.current();
        User user = new User();
        user.setId(current.getId());
        user.setName(current.getName());
        user.setUsername(current.getUsername());
        return user;
    }
    @GetMapping("allPermissionWithRole")
    public List<Permission> allPermissionWithRole(){
        return userService.allPermissionWithRole();
    }

    @GetMapping("allPermissionWithRole2")
    public List<Permission> allPermissionWithRole2(){
        return userService.allPermissionWithRole2();
    }
}
